﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestAddFactor.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Sequential.Tests.MatrixExtensionsTest.DoubleExtensions
{
    #region Usings

    using ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for <see cref="MatrixExtensions.Add(Matrix{double},double)"/>.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions.MatrixExtensions")]
    public sealed class TestAddFactor
    {
        #region Methods

        #region public

        /// <summary>
        ///     Tests the method when matrix has <see cref="CMDenseMatrix{T}"/> type.
        /// </summary>
        [Test]
        public void WhenMatrixHasCMDenseMatrixType()
        {
            // Arrange
            var data = new[]
                       {
                           new double[] { 1, 2 },
                           new double[] { 3, 4 },
                           new double[] { 5, 6 }
                       };
            var matrix = new CMDenseMatrix<double>(data);
            var expectedData = new[]
                               {
                                   new double[] { 11, 12 },
                                   new double[] { 13, 14 },
                                   new double[] { 15, 16 }
                               };

            // Act
            MatrixExtensions.Add(matrix, 10);

            // Assert
            Assert.That(matrix.Values, Is.EquivalentTo(expectedData));
        }

        /// <summary>
        ///     Tests the method when matrix has <see cref="CMFlattenDenseMatrix{T}"/> type.
        /// </summary>
        [Test]
        public void WhenMatrixHasCMFlattenDenseMatrixType()
        {
            // Arrange
            var data = new double[]
                       {
                           1, 2,
                           3, 4,
                           5, 6
                       };
            var matrix = new CMFlattenDenseMatrix<double>(2, 3, data);
            var expectedData = new double[]
                               {
                                   11, 12,
                                   13, 14,
                                   15, 16
                               };

            // Act
            MatrixExtensions.Add(matrix, 10);

            // Assert
            Assert.That(matrix.Values, Is.EquivalentTo(expectedData));
        }

        /// <summary>
        ///     Tests the method when matrix has <see cref="DenseSymmetricMatrix{T}"/> type.
        /// </summary>
        [Test]
        public void WhenMatrixHasDenseSymmetricMatrixType()
        {
            // Arrange
            var data = new double[]
                       {
                           1,
                           2, 3
                       };
            var matrix = new DenseSymmetricMatrix<double>(data);
            var expectedResult = new double[]
                                 {
                                     11,
                                     12, 13
                                 };

            // Act
            MatrixExtensions.Add(matrix, 10);

            // Assert
            Assert.That(matrix.Values, Is.EquivalentTo(expectedResult));
        }

        /// <summary>
        ///     Tests the method when matrix has <see cref="RMDenseMatrix{T}"/> type.
        /// </summary>
        [Test]
        public void WhenMatrixHasRMDenseMatrixType()
        {
            // Arrange
            var data = new[]
                       {
                           new double[] { 1, 2, 3 },
                           new double[] { 4, 5, 6 }
                       };
            var matrix = new RMDenseMatrix<double>(data);
            var expectedData = new[]
                               {
                                   new double[] { 11, 12, 13 },
                                   new double[] { 14, 15, 16 }
                               };

            // Act
            MatrixExtensions.Add(matrix, 10);

            // Assert
            Assert.That(matrix.Values, Is.EquivalentTo(expectedData));
        }

        /// <summary>
        ///     Tests the method when matrix has <see cref="RMFlattenDenseMatrix{T}"/> type.
        /// </summary>
        [Test]
        public void WhenMatrixHasRMFlattenDenseMatrixType()
        {
            // Arrange
            var data = new double[]
                       {
                           1, 2, 3,
                           4, 5, 6
                       };
            var matrix = new RMFlattenDenseMatrix<double>(2, 3, data);
            var expectedData = new double[]
                               {
                                   11, 12, 13,
                                   14, 15, 16
                               };

            // Act
            MatrixExtensions.Add(matrix, 10);

            // Assert
            Assert.That(matrix.Values, Is.EquivalentTo(expectedData));
        }

        #endregion

        #endregion
    }
}